package com.baoku.wap.util;

import java.sql.*;
/**
 * <p>
 * Copyright: Copyright (c) 2010-04-19
 * </p>
 * <p>
 * DB 封装
 * </p>
 * <p>
 * δ�޸�
 * </p>
 * @version 1.0
 * @see 
 * @author ���<�
 */
public class DB {

	public static Connection getConnection() {
		Connection conn = null; 
		try{
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection("jdbc:mysql://localhost/baoku_db?user=root&password=teago");
		} catch (final ClassNotFoundException e) {
			e.printStackTrace();
			DB.close(conn);
		} catch (final SQLException e) {
			e.printStackTrace();
			DB.close(conn);
		}
		return conn;
	}
	
	public static Statement getStatement(Connection conn) {
		Statement st = null;
		try {
			st = conn.createStatement();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return st;
	}
	
	
	public static void close(Connection conn) {
		try {
			if (conn != null)
			{
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void close(Statement st) {
		try {
			if (st != null) {
				st.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static void close(ResultSet rs) {
		try {
			if (rs != null){
				rs.close();				
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}